﻿namespace Main.lib.space
{

    /**
     * Two-dimensional space class
     * 
     * @author  Bruno Miguel de Oliveira Tamer <bmotamer@gmail.com>
     * @version 2011.11.25
     * 
     * @brief   Let you create a "lightweight" two-dimensional array
     * @param   Generic container type
     */
    public sealed class Map<T>
    {

        public readonly uint Width, Height; // Dimensions
        public readonly T[]  Data;          // Container

        /**
         * Constructor
         * 
         * @brief Creates the container
         * @param Width
         * @param Height
         */
        public Map(uint width, uint height)
        {
            Width  = width;
            Height = height;
            Data   = new T[Height * Width];
        }

        /**
         * Container accessor
         * 
         * @brief Let you get or set a position's value
         * @param X-coordinate
         * @param Y-coordinate
         */
        public T this[uint x = 0, uint y = 0]
        {
            get
            {
                return Data[x + y * Width];
            }
            set
            {
                Data[x + y * Width] = value;
            }
        }

    }

}